/**
 * Created by Dalyn on 2017/3/21.
 */
import React from "react";
import "./css/settlementProcess.css";
import Confirm from "../../common/Confirm";
import { message } from 'antd';
import { Button } from 'fly';
import {hashHistory,Link} from 'react-router';
import Relay from "react-relay";
import SettlementViewMutation from "./mutation/SettlementViewMutation"
import './css/settlementView.css';
import Config from "../../util/Config"
/*导出组件*/
export default class SettlementProcess extends React.Component{

    constructor(props) {
        super(props);
        this.state = {
            invoiceNum: '', //发票张数
            expressName: '', //快递公司
            expressSheet: '', //快递单号
            invoiceFileJson: [], //发票附件
            balanceMoney: '', //结算金额
            repayMoney: '', //还款金额
            remitFileJson: [], //汇款凭证

        };
        this.url = Config.qiuniu;
        this.settle = this.props.location.state.settle
    }
    componentWillMount(){
      this.settlementView()
    }
    settlementView() {
        Relay.Store.commitUpdate(
            new SettlementViewMutation({
                orderId: this.props.location.state.orderId,
            }),
            {
                onFailure: () => {
                    message.error("请求失败")
                },
                onSuccess: (response) => {
                    let data = response.enBalanceDetail.data;
                    if (data.errorCode === "0") {
                       this.setState({
                           invoiceNum: data.enterpriseBalance.invoiceNum,
                           expressName: data.enterpriseBalance.expressName,
                           expressSheet: data.enterpriseBalance.expressSheet,
                           invoiceFileJson: JSON.parse(data.enterpriseBalance.invoiceFileJson),
                           balanceMoney: data.enterpriseBalance.balanceMoney,
                           repayMoney: data.enterpriseBalance.repayMoney,
                           remitFileJson: JSON.parse(data.enterpriseBalance.remitFileJson),
                       })
                    } else {
                        this.setState({
                            hint: data.value
                        });
                    }
                }

            }
        );
    }
    /*点击返回*/
    handleCancel() {
        hashHistory.push("/settlementrecord")
    }
    /*营业执照*/
    downLoad_license(){
        window.open(Config.qiuniu+"E10adc3949ba59abbe56e057f20f883e-00001.jpg")
    }
    /*纳税人资质下载*/
    downLoad(){
        window.open(Config.qiuniu+"一般纳税人资质说明.docx")
    }
    render(){
        return (
          <div className="settlementView">
                <div className="settlementView_dash">
                    <div className="settlementView_box">
                        <p className="settlementView_title">发票信息</p>
                        <ul className="settlementView_box_ul">
                            <li>
                                <span className="settlementView_box_ul_title">发票张数:</span>
                                <span>{this.state.invoiceNum}</span>
                            </li>
                            <li>
                                <span className="settlementView_box_ul_title">快递公司:</span>
                                <span>{this.state.expressName}</span>
                            </li>
                            <li>
                                <span className="settlementView_box_ul_title">快递单号:</span>
                                <span>{this.state.expressSheet}</span>
                            </li>
                            <li>
                                <span className="settlementView_box_ul_title">发票附件:</span>
                                <p>
                                    {
                                        this.state.invoiceFileJson ? (
                                            this.state.invoiceFileJson.map((v,i)=>{
                                                return (<span className="settlementView_for">
                                                  <a>{v.name}</a>
                                                  {
                                                    v.response ? (<a target="_blank" href={this.url + v.response.key + `?attname=${v.name}`}>下载</a>) : null
                                                  }
                                                </span>)
                                            })
                                        ) : null
                                    }
                                </p>
                            </li>
                        </ul>
                    </div>
                    {
                        this.settle == 1 ? (
                            <div  className="settlementView_box">
                                <p className="settlementView_title">结算信息</p>
                                <ul className="settlementView_box_ul">
                                    <li>
                                        <span className="settlementView_box_ul_title">结算金额:</span>
                                        <span className="settlementView_red"> {this.state.balanceMoney}</span>&nbsp;元
                                    </li>
                                    <li>
                                        <span className="settlementView_box_ul_title">还款金额:</span>
                                        <span className="settlementView_red"> {this.state.repayMoney}</span>&nbsp;元
                                    </li>
                                    <li>
                                        <span className="settlementView_box_ul_title">汇款凭证:</span>
                                        <span>
                                         {

                                             this.state.remitFileJson ? (
                                                 this.state.remitFileJson.map((v,i)=>{
                                                    return ( <span className="settlementView_for">
                                                       <a>{v.name}</a>
                                                       {
                                                         v.response ? (<a target="_blank" href={this.url + v.response.key + `?attname=${v.name}`}>下载</a>) : null
                                                       }
                                                     </span>)
                                                 })
                                             ): null
                                         }
                                      </span>
                                    </li>
                                </ul>
                            </div>
                        ) : null
                    }

                    <div className="settlementView_btn"><Link to={'/settlementRecord'}><Button>返回</Button></Link></div>
                </div>
          </div>
        )
    }
}
